package com.stedu.service.impl;

import com.stedu.bean.RepairPersonnel;
import com.stedu.exception.SteduException;
import com.stedu.mapper.RepairPersonnelMapper;
import com.stedu.service.RepairPersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RepairPersonnelServiceImpl implements RepairPersonnelService {
    @Autowired
    private RepairPersonnelMapper repairPersonnelMapper;
    @Override
    public List<RepairPersonnel> selectByPname(String pname) throws SteduException {
        return repairPersonnelMapper.selectByPname(pname);
    }

    @Override
    public boolean insert(RepairPersonnel p) throws SteduException {
        if(repairPersonnelMapper.selectByPid(p.getPid()) !=null){
            throw new SteduException("该维修人员已经存在，无法重复添加");
        }
        return repairPersonnelMapper.insert(p) == 1;
    }

    @Override
    public boolean delete(Integer pid) throws SteduException {
        if (repairPersonnelMapper.selectByPid(pid) ==null){
            throw new SteduException("该维修人员不存在，无法删除");

        }
        return repairPersonnelMapper.delete(pid)==1;
    }

    @Override
    public boolean update(RepairPersonnel p) throws SteduException {
        if (repairPersonnelMapper.selectByPid(p.getPid()) == null){
            throw new SteduException("该维修人员不存在，无法修改");
        }
        return repairPersonnelMapper.update(p) == 1;
    }


    @Override
    public RepairPersonnel selectByPid(Integer pid) {
        return repairPersonnelMapper.selectByPid(pid);
    }

    @Override
    public List<RepairPersonnel> selectAll() {
        return repairPersonnelMapper.selectAll();
    }
}
